package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.dragon.repository.entity.Examine;
import com.dragon.repository.entity.ExamineUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 审核人员关联表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2024-02-27
 */
@Mapper
public interface ExamineUserMapper extends BaseMapper<ExamineUser> {


    /**
     * 获取即将审核的数据
     * @param streamType
     * @param correlationId
     * @return
     */
    @Select(" select deu.* from dragon_examine_user deu " +
            " left join dragon_examine de on deu.examine_id = de.id " +
            " where de.stream_type = #{streamType} and de.correlation_id = #{correlationId} " +
            " and de.status = 0 and deu.status = 0 and deu.pre_status = 1")
    List<ExamineUser> selectAuditListById(Integer streamType,Integer correlationId);

    @Select(" select de.*,deu.id examineUserId from dragon_examine_user deu " +
            " left join dragon_examine de on deu.examine_id = de.id " +
            " where de.stream_type = #{streamType} and de.correlation_id = #{correlationId} " +
            " and de.status = 0 and deu.status = 0 and deu.pre_status = 1 and deu.audit_user_id = #{adminId}")
    Examine selectAuditById(Integer adminId, Integer streamType, Integer correlationId);


    @Select(" select deu.*,da.username from dragon_examine_user deu left join dragon_admin da on deu.audit_user_id = da.id and da.state = 1 and da.deleted = 0 " +
            " ${ew.customSqlSegment} ")
    List<ExamineUser> selectAuditListByExamineId(@Param(Constants.WRAPPER) Wrapper<ExamineUser> wrapper);

}
